package com.oamicnet.servicetwo.server.controller;

import com.oamicnet.servicetwo.server.mq.MyCustomEvent;
import com.oamicnet.servicetwo.server.mq.OrderMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BusEventController {

    @Autowired
    private ApplicationEventPublisher publisher;

    @Autowired
    private BusProperties busProperties;

    @PostMapping("/bus/event")
    public String publishEvent(@RequestBody OrderMessage message) {
        MyCustomEvent event = new MyCustomEvent(this, "originService", "destinationService", message.toString());
        publisher.publishEvent(event);
        return "Event published: " + message;
    }
}
